package com.apes.fn.server.workOrder.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.apache.ibatis.annotations.Many;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 施工记录
 * Creator: zouyc
 * CreateDate: 2020-04-15 18:06
 * Description:
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ConstructionRecord.CONST_TABLE_NAME)
public class ConstructionRecord extends Model {
    public static final String CONST_TABLE_NAME = "ser_construction_record";

    public static final String CONST_TABLE_OPERATETYPE_START = "start";
    public static final String CONST_TABLE_OPERATETYPE_PAUSE = "pause";
    public static final String CONST_TABLE_OPERATETYPE_RENEW = "renew";
    public static final String CONST_TABLE_OPERATETYPE_FINISH = "finish";
    public static final String CONST_TABLE_OPERATETYPE_END = "end";


    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "施工记录编码", padding = 12)
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "maintenance_order", referencedColumnName = "id")
    @Comment("工单工时")
    private MaintenanceOrder maintenanceOrder;

    @States(name = "操作类型", values = {
            @State(id = "start", name = "施工"),
            @State(id = "pause", name = "暂停"),
            @State(id = "renew", name = "恢复施工"),
            @State(id = "finish", name = "完成施工"),
            @State(id = "end", name = "终止施工")
    })
    @Column(name = "state", length = 32, nullable = false)
    private String operateType = "start";

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "last_construction_record", referencedColumnName = "id")
    @Comment("上一步操作")
    private ConstructionRecord lastConstructionRecord;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "operate_reason", referencedColumnName = "id")
    @Comment("操作原因")
    private Enumeration operateReason;

}